home *** CD-ROM | disk | FTP | other *** search
/ LOGIC Apps / Logic-APPLE_II_APPS.iso / mac / LOGIC Apple II 5.25" Library - ProDOS / PRO024.dsk / PROBABILITY.bas < prev    next >
BASIC Source File  |  2012-02-16  |  28KB  |  546 lines

  1. 3  DIM F(12),WH$(20): REM   FOR TWO DICE SIMULATION & SLOT WHEEL
  2. 6  FOR I = 1 TO 20
  3. 7  READ WH$(I)
  4. 8  NEXT I
  5. 9  DATA    APPLE,PLUM,BELL,BAR,CHERRY,ORANGE,SEVEN,PLUM,BELL,BAR,CHERRY,ORANGE,PLUM,BELL,BAR,CHERRY,ORANGE,PLUM,BELL,BAR  
  6. 10  IF  PEEK(104) < >64  THEN  POKE 104,64: POKE 16384,0: POKE 214,85: PRINT  CHR$(4)"RUN  PROBABILITY": REM     LOAD PROGRAM ABOVE HGR PAGE 1
  7. 30  REM    NEWTON'S APPLE - PROBABILITY
  8. 40  REM         VERSION 3.04
  9. 50  REM         6-02-86  
  10. 55  REM   GAMBLING NOTICE ADDED 6-2-86
  11. 60 SCROLL$ = "<<< NEWTON'S APPLE >>>....": GOSUB 4290
  12. 70  HOME 
  13. 80  INVERSE 
  14. 90  HTAB 10: VTAB 10
  15. 100  PRINT "NEWTON'S APPLE PRESENTS"
  16. 110  HTAB 15: VTAB 15
  17. 120  FLASH 
  18. 130  PRINT "PROBABILITY"
  19. 140  NORMAL 
  20. 150  VTAB 24
  21. 160  FOR PAUSE = 1 TO 3300: NEXT 
  22. 170  INPUT "Press the RETURN key to continue...";Q$
  23. 180  GOSUB 4260: GOSUB 4120
  24. 190  VTAB 12: HTAB 10: INVERSE : PRINT "FREEWARE FROM DU PONT": NORMAL 
  25. 200  FOR I = 1 TO 2000: NEXT 
  26. 210  GOSUB 4260: GOSUB 4120
  27. 220  REM    Intro text starts here<CTRL-J><CTRL-J>
  28. 230  HTAB 8
  29. 240  PRINT "<CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C><CTRL-C>PROBABILITY - What is it?
  30. 250  VTAB 8
  31. 260  PRINT "PROBABILITY is the likeliness that an   event will happen.  If an event is very likely to happen, we say the            PROBABILITY of the event is HIGH."
  32. 270  PRINT : PRINT : PRINT 
  33. 280  PRINT "On the other hand, if an event is not   likely to happen, we say the            PROBABILITY is LOW."
  34. 290  VTAB 24
  35. 300  INPUT "Press return to continue...";Q$
  36. 310  REM     *** WIPE ***<CTRL-J><CTRL-J>
  37. 320  GOSUB 4160
  38. 330  PRINT "Check your understanding..."
  39. 340  REM    *** FIRST QUIZ ***<CTRL-J><CTRL-J>
  40. 350  VTAB 10
  41. 360  PRINT "If an event is VERY likely to happen    we say that the PROBABILITY of the      event is:
  42. 370  PRINT : PRINT 
  43. 380  HTAB 10:
  44. 390  PRINT "A) LOW
  45. 400  PRINT : PRINT : PRINT 
  46. 410  HTAB 10
  47. 420  PRINT "B) HIGH"
  48. 430  VTAB 23
  49. 440  INPUT "Enter the letter for the best choice: ";Q$
  50. 450  IF Q$ = "b"  OR Q$ = "B"  THEN 520: REM     GOT IT RIGHT!
  51. 460  IF Q$ < >"a"  AND Q$ < >"A"  THEN 430
  52. 470  HOME : VTAB 8
  53. 480  PRINT "Sorry, that's not right.  Take another  look at our definition for PROBABILITY."
  54. 490  VTAB 23:
  55. 500  INPUT "Press return to review...";Q$
  56. 510  GOTO 210
  57. 520  GOSUB 4220
  58. 530  GOSUB 4570
  59. 540  VTAB 8
  60. 550  PRINT "Good job, the probability would be high"
  61. 560  VTAB 23: INPUT "Press return to learn more...";Q$
  62. 570  REM    *** ZERO AND ONE **** 
  63. 580  HOME 
  64. 590  HTAB 12
  65. 600  INVERSE : PRINT "ZERO OR ONE ???": NORMAL 
  66. 610  PRINT : PRINT 
  67. 620  PRINT "The probability of an event can be      expressed with numbers:"
  68. 630  VTAB 10
  69. 640  PRINT "If there is NO CHANCE of an event       happening, the probability is said to   be 0 (zero)."
  70. 650  VTAB 17
  71. 660  PRINT "If there is EVERY chance that an event  will happen, the probability is said to be 1 (one)."
  72. 670  VTAB 23
  73. 680  INPUT "Press return to continue...";Q$
  74. 690  HOME 
  75. 700  HTAB 5
  76. 710  PRINT "Time for another little quiz.."
  77. 720  VTAB 8
  78. 730  PRINT "If there is NO WAY that an event can    happen, the probability of that event   is:"
  79. 740  PRINT 
  80. 750  PRINT  TAB( 15);"A) One"
  81. 760  PRINT 
  82. 770  PRINT  TAB( 15);"B) Zero"
  83. 780  VTAB 22
  84. 790  INPUT "Please choose the letter of the correct answer: ";Q$
  85. 800  IF Q$ = "B"  OR Q$ = "b"  THEN 880: REM     GOT IT RIGHT!
  86. 810  IF Q$ < >"a"  AND Q$ < >"A"  THEN 780
  87. 820  HOME 
  88. 830  VTAB 10
  89. 840  PRINT "Oops! That's not right.....Better review a bit..."
  90. 850  VTAB 23
  91. 860  INPUT "Press return to try again...";Q$
  92. 870  GOTO 580
  93. 880  GOSUB 4220
  94. 890  GOSUB 4570
  95. 900  HTAB 15: VTAB 11: FLASH : PRINT "GREAT JOB!!!": NORMAL 
  96. 910  VTAB 23
  97. 920  INPUT "Press return to continue...";Q$
  98. 930  GOSUB 4140
  99. 940  VTAB 9
  100. 950  PRINT "Some events, such as the flipping of a  coin have TWO possible outcomes. In     these cases a little arithmetic will    help us to calculate the probability    of the event coming out one particular  way."
  101. 960  VTAB 23
  102. 970  INPUT "Press return for more...";Q$
  103. 980  GOSUB 4160
  104. 990  PRINT "In the case of a flipped coin, there    are TWO possible results (HEADS and     TAILS).
  105. 1000  PRINT : PRINT : PRINT "To calculate the PROBABILITY of getting Heads on a flip we must divide the      number of ways of winning (getting      heads) by the total possible outcomes.  In our example the total number of"
  106. 1010  PRINT "possible outcomes is TWO (Heads or      TAILS)."
  107. 1020  PRINT : PRINT : PRINT "Ways to get HEADS = 1
  108. 1030  PRINT : PRINT "Total possible outcomes = 2
  109. 1040  PRINT : PRINT "Probability of getting HEADS:"
  110. 1050  PRINT : PRINT "1 divided by 2 = .5"
  111. 1060  VTAB 24
  112. 1070  INPUT "Press return for more...";Q$
  113. 1080  GOSUB 4160
  114. 1090  PRINT "Notice that the probability will be     expressed as a decimal number between   zero and one."
  115. 1100  VTAB 10
  116. 1110  PRINT "A probability of .5 (or one half) means that if you flip a coin many times,     it will come up heads about half of the time."
  117. 1120  VTAB 23
  118. 1130  INPUT "Press return for more...";Q$
  119. 1140  GOSUB 4140
  120. 1150  HTAB 10: INVERSE : PRINT "MAKING A PREDICTION": NORMAL 
  121. 1160  PRINT : PRINT 
  122. 1170  PRINT "Once you have calculated the            probability of an event (such as a coin coming up heads), you can predict (make an educated guess) how many HEADS you   should get from a total number of flips"
  123. 1180  PRINT : PRINT : PRINT "Take the CALCULATED PROBABILITY (.5 for our example) and multiply it by the     total number of trials (coin flips in   our example)
  124. 1190  VTAB 23
  125. 1200  INPUT "Press return for an example...";Q$
  126. 1210  GOSUB 4180
  127. 1220  HTAB 9: INVERSE : PRINT "CALCULATING OUR GUESS": NORMAL 
  128. 1230  PRINT : PRINT : PRINT  TAB( 29);"EXPECTED"
  129. 1240  PRINT "PROBABILITY x # OF TRIALS = FAVORABLE"
  130. 1250  PRINT  TAB( 29);"OUTCOMES"
  131. 1260  PRINT : PRINT "For our coin flip example:"
  132. 1270  PRINT : PRINT : PRINT ".5 x NUMBER OF TRIALS = EXPECTED HEADS"
  133. 1280 N =  INT( RND(8) *200 +2)
  134. 1290  PRINT : PRINT : PRINT "If we flipped a coin ";N;" times, how": INPUT "many HEADS would you predict? ";Q$
  135. 1300  IF  ABS(N/2 - VAL(Q$)) <1.1  THEN  GOSUB 4570: VTAB 10: PRINT : INVERSE : PRINT "GOOD!";: NORMAL : PRINT " YOU HAVE THE IDEA!": GOTO 1330
  136. 1310  PRINT : PRINT : INVERSE : PRINT "OOPS! ";: NORMAL : PRINT "Try again.": VTAB 24: INPUT "Press return for another try...";Q$
  137. 1320  GOTO 1140: REM   GOT IT WRONG - RELEARN
  138. 1330  VTAB 23: INPUT "Press return to try out your prediction";Q$
  139. 1340  GOSUB 4160: REM    START COIN FLIP SIMULATION<CTRL-J><CTRL-J>
  140. 1350  PRINT "Sometimes a computer can be used to     SIMULATE an experiment.  Computer       simulations are useful when you don't   have the time or materials for a real   experiment."
  141. 1360  VTAB 20
  142. 1370  INPUT "Press return and you can SIMULATE the   flipping of a coin...";Q$
  143. 1380  GOSUB 4120: REM     COIN FLIP SIMULATION
  144. 1390  HTAB 5: INVERSE : PRINT "COIN FLIP - COMPUTER SIMULATION": NORMAL 
  145. 1400  PRINT 
  146. 1410  INPUT "How many times would you like to flip   the coin? ";Q$
  147. 1420 N =  VAL(Q$)
  148. 1430  IF N <1  THEN  CALL  -868: GOTO 1410
  149. 1440  PRINT 
  150. 1450  INPUT "How many HEADS do you predict? ";Q$
  151. 1460 P =  VAL(Q$)
  152. 1470  PRINT 
  153. 1480  VTAB 23: PRINT "Flipping coin ";N;" times..."
  154. 1490  REM    *** FLIPPING COIN ***<CTRL-J><CTRL-J>
  155. 1500  VTAB 21: HTAB 7: PRINT "HEADS" TAB( 31);"TAILS"
  156. 1510 HEADS = 0:TAILS = 0
  157. 1520  GR 
  158. 1530  COLOR= 15
  159. 1540  HLIN 1,14 AT 38: REM   BASE LINE
  160. 1550  HLIN 25,39 AT 38: REM   BASE LINE
  161. 1560  REM   *** GRAPH FLIPS ***<CTRL-J><CTRL-J>
  162. 1570  FOR I = 1 TO N
  163. 1580 COIN =  INT( RND(8) +.5)
  164. 1590  IF COIN <.5  THEN TAILS = TAILS +1
  165. 1600  IF COIN > = .5  THEN HEADS = HEADS +1
  166. 1610  IF N <38  THEN  HLIN 1,14 AT 38 -HEADS: HLIN 25,39 AT 38 -TAILS: GOTO 1640
  167. 1620  HLIN 1,14 AT 38 -(HEADS *38/N)
  168. 1630  HLIN 25,39 AT 38 -(TAILS *38/N)
  169. 1640  NEXT 
  170. 1650  VTAB 22: PRINT  TAB( 5);HEADS;" times"; TAB( 30);TAILS;" times"
  171. 1660  PRINT "Experimental results: ";HEADS;" / ";N;" = ";HEADS/N
  172. 1670  INPUT "Press return for a summary...";Q$
  173. 1680  HOME : TEXT : HOME 
  174. 1690  HTAB 11: INVERSE : PRINT "SUMMARY OF RESULTS": NORMAL 
  175. 1700  PRINT : PRINT "NUMBER OF TRIALS = ";N
  176. 1710  PRINT : PRINT "PREDICTED HEADS = ";P
  177. 1720  PRINT : PRINT "ACTUAL HEADS = ";HEADS
  178. 1730  IF HEADS = 0  THEN  PRINT : PRINT : PRINT "EXPERIMENTAL VALUE FOR HEADS IS ZERO.   WE CAN'T MAKE A PERCENT COMPARISON.": GOTO 1750: REM   AVOID DIV BY 0 ERROR
  179. 1740  PRINT : PRINT : PRINT "DIFFERENCE BETWEEN PREDICTED HEADS AND  EXPERIMENTAL RESULTS = "; INT( ABS((HEADS -P) *100/HEADS) +.5);" PERCENT"
  180. 1750  IF F1 = 1  THEN 1830: REM    WE'VE ALREADY READ THIS 
  181. 1760  PRINT : PRINT : PRINT : PRINT "As you can see, the predicted result    does not exactly match the experimental result."
  182. 1770  VTAB 23: INPUT "Press return for an explanation...";Q$
  183. 1780  GOSUB 4160
  184. 1790  PRINT : PRINT "This is because probability is the      PROBABLE outcome of an event.  It is    possible (but unlikely) that you could  flip a coin 1000 times and its would    come up heads 1000 times!"
  185. 1800  PRINT : PRINT "Each flip is an independant event and   it is not affected by any other flip.   Got it?"
  186. 1810 F1 = 1: REM    WE'VE READ THIS ONCE!!
  187. 1820  PRINT : PRINT : PRINT : PRINT : PRINT : PRINT "Now you have a choice:"
  188. 1830  VTAB 18: PRINT  TAB( 11);"A) Flip coins again"
  189. 1840  PRINT : PRINT  TAB( 11);"B) Explore further"
  190. 1850  PRINT : PRINT  TAB( 11);"C) Quit"
  191. 1860  PRINT : INPUT "Enter your choice: ";Q$
  192. 1870  IF Q$ = "A"  OR Q$ = "a"  THEN 1380
  193. 1880  IF Q$ = "B"  OR Q$ = "b"  THEN 1920
  194. 1890  IF Q$ = "C"  OR Q$ = "c"  THEN 3950: REM   LAST CHANCE MENU
  195. 1900  PRINT "Please enter A, B or C": GOTO 1860
  196. 1910  REM   *** BEGIN NEXT SECTION<CTRL-J><CTRL-J>
  197. 1920  HOME 
  198. 1930  INVERSE : HTAB 6: PRINT "AND NOW SOMETHING DIFFERENT": NORMAL 
  199. 1940  PRINT : PRINT "If we take a cube and number the sides  from one to six we have a DIE.          (singular of dice!).
  200. 1950 X =  INT( RND(8) *6 +1)
  201. 1960  PRINT : PRINT "What would be the probability of        rolling a ";X;" with a single die?
  202. 1970  PRINT : PRINT  TAB( 10);"A) 0"
  203. 1980  PRINT : PRINT  TAB( 10);"B) .25"
  204. 1990  PRINT : PRINT  TAB( 10);"C) .17"
  205. 2000  PRINT : PRINT  TAB( 10);"D) 6
  206. 2010  PRINT : PRINT  TAB( 10);"E) ";X
  207. 2020  PRINT : PRINT  TAB( 10);"F) Help!"
  208. 2030  PRINT : INPUT "Enter the letter of the answer: ";Q$
  209. 2040  IF Q$ = "C"  OR Q$ = "c"  THEN 2100
  210. 2050  IF Q$ = "F"  OR Q$ = "f"  THEN 2150
  211. 2060  HOME : VTAB 8: PRINT "I'm sorry, but that's not right."
  212. 2070  VTAB 23
  213. 2080  INPUT "Press return for some help...";Q$
  214. 2090  GOTO 2150: REM   GET HELP SCREEN
  215. 2100  GOSUB 4160
  216. 2110  GOSUB 4570: VTAB 11: HTAB 11: INVERSE : PRINT "GOOD JOB !!!": NORMAL 
  217. 2120  FOR I = 1 TO 500: NEXT 
  218. 2130  PRINT : PRINT : PRINT "That's right.  There is only one way to get a ";X;" and 6 possible outcomes for     rolling a single die. So the answer had to be 1/6 = .17": VTAB 23: INPUT "Press return to continue...";Q$: GOTO 2260
  219. 2140  REM   *** HELP ***<CTRL-J><CTRL-J>
  220. 2150  GOSUB 4160
  221. 2160  HTAB 4: INVERSE : PRINT "HELP FROM YOUR FRIENDLY COMPUTER": NORMAL 
  222. 2170  PRINT : PRINT "Remember the rule for calculating the   probability of an event:"
  223. 2180  PRINT : PRINT "Ways to get a favorable outcome divided by total possible outcomes = PROBABILITY"
  224. 2190  PRINT : PRINT "Ways to get a ";X;" ... 1"
  225. 2200  PRINT : PRINT "Total possible outcomes ... 6"
  226. 2210  PRINT : PRINT "So:"
  227. 2220  PRINT : PRINT  TAB( 10);"1 / 6 = .17"
  228. 2230  VTAB 23: INPUT "Press return for another chance...";Q$
  229. 2240  GOTO 1920: REM   BACK TO THE QUESTION
  230. 2250  REM   *** PROG CONTINUES ***<CTRL-J><CTRL-J>
  231. 2260  GOSUB 4120
  232. 2270  HTAB 12: INVERSE : PRINT "MORE FUN STUFF !!": NORMAL 
  233. 2280  PRINT : PRINT 
  234. 2290  PRINT "Now you will have a chance to test the  expected .17 probability of a single    roll of a die.  You will be given the   opportunity to roll a single die many   times.  The computer will show you what
  235. 2300  PRINT "number has come up for each roll.  
  236. 2310  PRINT "The computer will also show what        percent of the total rolls is           represented by each face of the die."
  237. 2320  PRINT : PRINT : PRINT 
  238. 2330  PRINT : PRINT "It should be noted that the expected    probability of .17 would be 17 percent  as displayed by the computer."
  239. 2340  VTAB 23
  240. 2350  INPUT "Press return to roll the die...";Q$
  241. 2360  REM  <CTRL-J><CTRL-J>***  SINGLE DIE ROLL ***<CTRL-J><CTRL-J>
  242. 2370  HOME 
  243. 2380  FOR I = 1 TO 6:R(I) = 0: NEXT : REM   CLEAR ARRAY
  244. 2390 N = 0
  245. 2400  HTAB 11
  246. 2410  INVERSE 
  247. 2420  PRINT "COMPUTER SIMULATION"
  248. 2430  HTAB 10
  249. 2440  PRINT "ROLLS OF A SINGLE DIE"
  250. 2450  NORMAL 
  251. 2460  VTAB 4: PRINT " NUMBER OF ROLLS: "
  252. 2470  PRINT 
  253. 2480  PRINT "   NUMBER     TIMES      PERCENT"
  254. 2490  PRINT "    THAT      NUMBER       OF"
  255. 2500  PRINT "   CAME UP    CAME UP     ROLLS"
  256. 2510  PRINT "   -------    -------     -----"
  257. 2520  HTAB 6: VTAB 11: PRINT "1"
  258. 2530  HTAB 6: VTAB 13: PRINT "2"
  259. 2540  HTAB 6: VTAB 15: PRINT "3"
  260. 2550  HTAB 6: VTAB 17: PRINT "4"
  261. 2560  HTAB 6: VTAB 19: PRINT "5"
  262. 2570  HTAB 6: VTAB 21: PRINT "6"
  263. 2580  VTAB 23: PRINT "SPACE BAR TO STOP ANY OTHER KEY TO GO"
  264. 2590  PRINT "        C TO CONTINUE Q TO QUIT";
  265. 2600  REM   <CTRL-J><CTRL-J>**  TOP OF LOOP **
  266. 2610 X =  INT( RND(8) *6) +1
  267. 2620 N = N +1
  268. 2630 R(X) = R(X) +1
  269. 2640  HTAB 19: VTAB 4: PRINT N
  270. 2650  HTAB 17: VTAB 11: PRINT R(1)
  271. 2660  HTAB 17: VTAB 13: PRINT R(2)
  272. 2670  HTAB 17: VTAB 15: PRINT R(3)
  273. 2680  HTAB 17: VTAB 17: PRINT R(4)
  274. 2690  HTAB 17: VTAB 19: PRINT R(5)
  275. 2700  HTAB 17: VTAB 21: PRINT R(6)
  276. 2710  HTAB 28: VTAB 11: PRINT  INT(R(1) *100/N +.5);" "
  277. 2720  HTAB 28: VTAB 13: PRINT  INT(R(2) *100/N +.5);" "
  278. 2730  HTAB 28: VTAB 15: PRINT  INT(R(3) *100/N +.5);" "
  279. 2740  HTAB 28: VTAB 17: PRINT  INT(R(4) *100/N +.5);" "
  280. 2750  HTAB 28: VTAB 19: PRINT  INT(R(5) *100/N +.5);" "
  281. 2760  HTAB 28: VTAB 21: PRINT  INT(R(6) *100/N +.5);" "
  282. 2770  POKE  -16384,0
  283. 2780 K =  PEEK( -16384) -128: IF K = 32  THEN  FOR P = 1 TO 30: NEXT P: GET Q$: GET Q$: POKE  -16384,0
  284. 2790  IF K = 67  OR K = 99  THEN  GET Q$: POKE  -16384,0: GOTO 2830
  285. 2800  IF K = 81  OR K = 113  THEN  GET Q$: POKE  -16384,0: GOTO 3950
  286. 2810  GOTO 2610
  287. 2820  REM  <CTRL-J><CTRL-J>***  PART 3 - TWO DICE ***<CTRL-J><CTRL-J>
  288. 2830  GOSUB 4160
  289. 2840  HTAB 12: INVERSE : PRINT "EXTRA CHALLENGE": NORMAL 
  290. 2850  PRINT 
  291. 2860  PRINT "A more challenging problem can be posed by calculating the probability of each  sum that results from adding the rolls  of two six sided dice."
  292. 2870  FOR P = 1 TO 5000: NEXT 
  293. 2880  PRINT : PRINT "See if you can calculate the            probability of each sum that can be     produced by rolling two dice."
  294. 2890  FOR P = 1 TO 5000: NEXT 
  295. 2900  PRINT : PRINT "To do this you will need to make a      table of all the combinations of a two  dice roll. (There are 36 combinations)"
  296. 2910  VTAB 23: INPUT "Press return  for a sample table ";Q$
  297. 2920  GOSUB 4140
  298. 2930  PRINT "You need to find all the ways of        rolling a two, all the ways of rolling  a three and so on.  One way to do this  is to write out a table showing all the possible ways that two dice can roll."
  299. 2940  PRINT : PRINT "DIE 1      DIE 2      SUM"
  300. 2950  PRINT "-----      -----      ---"
  301. 2960  PRINT : PRINT "  1          1         2"
  302. 2970  PRINT : PRINT "  1          2         3"
  303. 2980  PRINT : PRINT "  1          3         4"
  304. 2990  PRINT : PRINT "  1          4         5"
  305. 3000  PRINT : PRINT "  1          5         6"
  306. 3010  PRINT : PRINT "  1          6         7"
  307. 3020  PRINT : PRINT "  2          1         3"
  308. 3030  HTAB 32: VTAB 12: PRINT "Here"
  309. 3040  HTAB 33: PRINT "is"
  310. 3050  HTAB 34: PRINT "a"
  311. 3060  HTAB 31: PRINT "partial"
  312. 3070  HTAB 32: PRINT "table"
  313. 3080  VTAB 24: INPUT "Press return to continue... ";Q$
  314. 3090  GOSUB 4140
  315. 3100  REM   <CTRL-J><CTRL-J>
  316. 3110  HTAB 11: INVERSE : PRINT "NOW IT'S YOUR TURN": NORMAL 
  317. 3120  VTAB 5: PRINT "Complete the table on a piece of paper. Then count how many ways there are to   roll a two by adding the numbers on the two dice."
  318. 3130  VTAB 23: INPUT "Press return when your chart is complete";Q$
  319. 3140  REM   <CTRL-J><CTRL-J>**** WIPE ***<CTRL-J><CTRL-J>
  320. 3150  GOSUB 4120
  321. 3160  PRINT : PRINT : PRINT "Remember:"
  322. 3170  PRINT : PRINT "PROBABILITY = WAYS TO GET A 2/TOTAL WAYS"
  323. 3180  PRINT : PRINT : PRINT "If you check your chart, you will find  that there is only one way to roll a    two. (DIE 1 = 1 and DIE 2 = 1)"
  324. 3190  PRINT : PRINT : PRINT "By counting all the combinations on     your chart, you should see that there   are 36 TOTAL WAYS that the dice can     roll."
  325. 3200  PRINT : PRINT "Use the formula to calculate the        PROBABILITY of rolling a TWO (Your      answer should be a decimal rounded to   the hundredths place)
  326. 3210  VTAB 24: INPUT "Press return when you have your answer ";Q$
  327. 3220  REM   <CTRL-J><CTRL-J>*** WIPE **<CTRL-J><CTRL-J>
  328. 3230  HOME 
  329. 3240  VTAB 8: PRINT "What is the probability of rolling two"
  330. 3250  PRINT "dice and having their sum equal TWO? "
  331. 3260  PRINT : PRINT "Type in your answer.  Don't forget to   type in the decimal point and round to  the hundredths place (two numbers after the decimal point)
  332. 3270  PRINT : PRINT 
  333. 3280  INPUT "Your answer? --> ";Q$
  334. 3290  IF  LEFT$(Q$,1) < >"0"  AND  LEFT$(Q$,1) < >"."  THEN 3230: REM   NOT A DECIMAL
  335. 3300  IF  VAL(Q$) = .03  THEN  GOSUB 4220: GOSUB 4570: VTAB 10: HTAB 14: INVERSE : PRINT "GOOD JOB !!!": NORMAL : GOTO 3380
  336. 3310  IF  ABS( VAL(Q$) -.027777) <.01  THEN  HOME : VTAB 10: PRINT "That's pretty close!": PRINT : PRINT "You may not have rounded quite right.": GOTO 3380
  337. 3320  HOME 
  338. 3330 : INVERSE : HTAB 16: PRINT "OOPS !!!": NORMAL 
  339. 3340  VTAB 10: PRINT "Sorry, that's not the answer."
  340. 3350  PRINT : PRINT "You want to divide the WAYS TO ROLL A   TWO by the TOTAL POSSIBLE ROLLS"
  341. 3360  VTAB 23: INPUT "Press return to continue...";Q$
  342. 3370  GOTO 3150: REM   TRY AGAIN
  343. 3380  VTAB 23: INPUT "Press return to do an experiment...";Q$
  344. 3390  REM   <CTRL-J><CTRL-J>*** WIPE ***<CTRL-J><CTRL-J>
  345. 3400  GOSUB 4160
  346. 3410  HTAB 11: INVERSE : PRINT "MAKING PREDICTIONS": NORMAL 
  347. 3420  PRINT : PRINT "Now calculate the probabilities for     rolling each of the possible sums of a  two dice roll."
  348. 3430  PRINT : PRINT "Write your answers down as you go. When you have calculated all the answers     (there are 11 answers in all) you can   do another computer simulated           experiment."
  349. 3440  VTAB 23: INPUT "Press return to get experimental data..";Q$
  350. 3450 N = 0:SUM = 0: FOR I = 2 TO 12:F(I) = 0: NEXT 
  351. 3460  REM   <CTRL-J><CTRL-J>*** 2 DICE SIMULATION ***<CTRL-J><CTRL-J>
  352. 3470  REM  <CTRL-J><CTRL-J>*** WIPE ***<CTRL-J><CTRL-J>
  353. 3480  GOSUB 4120: HTAB 10: INVERSE : PRINT "COMPUTER SIMULATION"
  354. 3490  HTAB 13: PRINT "TWO DICE ROLL": NORMAL 
  355. 3500  PRINT : PRINT "TOTAL"
  356. 3510  PRINT "TIMES          SUM   TIMES   PERCENT OF"
  357. 3520  PRINT "ROLLED:         OF    SUM      TOTAL"
  358. 3530  PRINT  TAB( 16);"DICE  ROLLED    ROLLS"
  359. 3540  PRINT  TAB( 16);"----  ------  ----------"
  360. 3550  FOR I = 10 TO 20: VTAB I: HTAB 17: PRINT I -8: NEXT 
  361. 3560  VTAB 10: PRINT "DIE ONE:"
  362. 3570  VTAB 12: PRINT "DIE TWO:"
  363. 3580  VTAB 14: HTAB 5: PRINT "SUM:"
  364. 3590  VTAB 24: PRINT "PRESS SPACE BAR TO PAUSE";
  365. 3600  REM   <CTRL-J><CTRL-J>*** TOP OF LOOP ***<CTRL-J><CTRL-J>
  366. 3610 N = N +1
  367. 3620 D1 =  INT(6 * RND(8) +1)
  368. 3630 D2 =  INT(6 * RND(8) +1)
  369. 3640 SUM = D1 +D2
  370. 3650 F(SUM) = F(SUM) +1
  371. 3660  VTAB 6: HTAB 8: PRINT N
  372. 3670  VTAB 10: HTAB 10: PRINT D1
  373. 3680  VTAB 12: HTAB 10: PRINT D2
  374. 3690  VTAB 14: HTAB 10: PRINT SUM;" "
  375. 3700  VTAB 10: HTAB 24: PRINT F(2); TAB( 32); INT(F(2) *100/N +.5);"  "
  376. 3710  VTAB 11: HTAB 24: PRINT F(3); TAB( 32); INT(F(3) *100/N +.5);"  "
  377. 3720  VTAB 12: HTAB 24: PRINT F(4); TAB( 32); INT(F(4) *100/N +.5);"  "
  378. 3730  VTAB 13: HTAB 24: PRINT F(5); TAB( 32); INT(F(5) *100/N +.5);"  "
  379. 3740  VTAB 14: HTAB 24: PRINT F(6); TAB( 32); INT(F(6) *100/N +.5);"  "
  380. 3750  VTAB 15: HTAB 24: PRINT F(7); TAB( 32); INT(F(7) *100/N +.5);"  "
  381. 3760  VTAB 16: HTAB 24: PRINT F(8); TAB( 32); INT(F(8) *100/N +.5);"  "
  382. 3770  VTAB 17: HTAB 24: PRINT F(9); TAB( 32); INT(F(9) *100/N +.5);"  "
  383. 3780  VTAB 18: HTAB 24: PRINT F(10); TAB( 32); INT(F(10) *100/N +.5);"  "
  384. 3790  VTAB 19: HTAB 24: PRINT F(11); TAB( 32); INT(F(11) *100/N +.5);"  "
  385. 3800  VTAB 20: HTAB 24: PRINT F(12); TAB( 32); INT(F(12) *100/N +.5);"  "
  386. 3810  POKE  -16368,0:K =  PEEK( -16384): IF K = 32  THEN 3840
  387. 3820  GOTO 3610
  388. 3830  REM  <CTRL-J><CTRL-J>*** WIPE ***<CTRL-J><CTRL-J>
  389. 3840  GOSUB 4120
  390. 3850  HTAB 10: INVERSE : PRINT "CHECK YOUR PREDICTION": NORMAL 
  391. 3860  PRINT 
  392. 3870  PRINT "Check to see how your calculated        probabilities compare with the          experimental results.  To compare       probability to percent, just multiply   your probability by 100!"
  393. 3880  PRINT : PRINT "The reliability of the experimental     result will increase as the number of   rolls increases so you might want to letthe simulation go for a while."
  394. 3890  VTAB 22: PRINT "Press 'E' to end the simulation"
  395. 3900  PRINT "Press return to continue...";
  396. 3910  GET Q$: IF Q$ = "E"  OR Q$ = "e"  THEN  GOTO 11030: REM     SLOTS
  397. 3920  IF Q$ =  CHR$(13)  THEN 3480: REM     CONTINUE SIMULATION
  398. 3930  GOTO 3910: REM    MUST BE 13 OR E
  399. 3940  REM  <CTRL-J><CTRL-J>*** WIPE ***
  400. 3950  GOSUB 4160
  401. 3960  HTAB 12: INVERSE : PRINT "LAST CHANCE MENU": NORMAL 
  402. 3970  PRINT : PRINT 
  403. 3980  PRINT "I hope you have had fun and learned a   little about probability."
  404. 3990  PRINT : PRINT "Here are your choices:"
  405. 4000  PRINT : PRINT  TAB( 5);"A) Coin toss"
  406. 4010  PRINT : PRINT  TAB( 5);"B) Roll one die"
  407. 4020  PRINT : PRINT  TAB( 5);"C) Roll two dice"
  408. 4030  PRINT : PRINT  TAB( 5);"D) Play the slots"
  409. 4035  PRINT : PRINT  TAB( 5);"E) Quit"
  410. 4040  VTAB 23: INPUT "Enter your choice and press return: ";Q$
  411. 4050  IF Q$ = "a"  OR Q$ = "A"  THEN 1380
  412. 4060  IF Q$ = "b"  OR Q$ = "B"  THEN 2260
  413. 4070  IF Q$ = "c"  OR Q$ = "C"  THEN 3450
  414. 4080  IF Q$ = "d"  OR Q$ = "D"  THEN 11000
  415. 4085  IF Q$ = "e"  OR Q$ = "E"  THEN 4580
  416. 4090  GOTO 4040
  417. 4100  REM   <CTRL-J><CTRL-J>*** WIPE SUBROUTINES ***<CTRL-J><CTRL-J>
  418. 4110  REM   LEFT/RIGHT WIPE
  419. 4120  FOR I = 1 TO 40: POKE 33,I: HOME : GOSUB 4270: NEXT : RETURN 
  420. 4130  REM   RIGHT/LEFT WIPE
  421. 4140  FOR I = 39 TO 0  STEP  -1: POKE 32,I: POKE 33,40 -I: HOME : GOSUB 4270: NEXT : RETURN 
  422. 4150  REM   CENTER OUT WIPE
  423. 4160  FOR I = 1 TO 20: POKE 32,20 -I: POKE 33,2 *I: HOME : GOSUB 4270: NEXT : RETURN 
  424. 4170  REM   UP WIPE
  425. 4180  FOR I = 24 TO 1  STEP  -1: VTAB I: HTAB 1: CALL  -868: GOSUB 4270: NEXT : RETURN 
  426. 4210  REM   STRIPE WIPE
  427. 4220  INVERSE : FOR I = 1 TO 24: VTAB I: HTAB 1: INVERSE : PRINT  SPC( 40): VTAB I: HTAB 1: NORMAL : PRINT  SPC( 40): NEXT : HOME : RETURN 
  428. 4250  REM   HYPE WIPE
  429. 4260  VTAB 1: HTAB 1: FOR I = 1 TO 23: PRINT "NEWTON'S APPLE.       NEWTON'S APPLE.    ";: NEXT : FOR J = 1 TO 500: NEXT : RETURN 
  430. 4270  FOR J = 1 TO 22: NEXT : RETURN 
  431. 4280  REM  <CTRL-J><CTRL-J>***  APPLE LOGO SUBROUTINE ***<CTRL-J><CTRL-J>
  432. 4290  HOME 
  433. 4300  REM  <CTRL-J><CTRL-J>SCROLL$ STORES MESSAGE<CTRL-J><CTRL-J>
  434. 4310  HGR 
  435. 4320  REM  <CTRL-J><CTRL-J>NEXT HCOLOR IS FOR BODY OF THE APPLE<CTRL-J><CTRL-J>
  436. 4330  HCOLOR= 3
  437. 4340  FOR I = 1 TO 22
  438. 4350  READ X,Y,X1,Y1
  439. 4360  HPLOT X +85,Y TO X1 +85,Y1
  440. 4370  HPLOT 193 -X,Y TO 193 -X1,Y1
  441. 4380  NEXT I
  442. 4390  REM  <CTRL-J><CTRL-J>NEXT HCOLOR IS FOR LEAF OF THE APPLE<CTRL-J><CTRL-J>
  443. 4400  HCOLOR= 3
  444. 4410  FOR I = 1 TO 15
  445. 4420  REM  <CTRL-J><CTRL-J>NEXT HCOLOR IS FOR STEM OF THE APPLE<CTRL-J><CTRL-J>
  446. 4430  IF I = 6  THEN  HCOLOR= 3
  447. 4440  READ X,Y,X1,Y1
  448. 4450  HPLOT X +85,Y TO X1 +85,Y1
  449. 4460  NEXT I
  450. 4470  VTAB 23:A$ = SCROLL$ +"        PRESS ANY KEY TO CONTINUE.....     "
  451. 4480  POKE  -16368,0
  452. 4490  HTAB 1: PRINT  LEFT$(A$,39);:A$ =  MID$ (A$,2) + LEFT$(A$,1):K =  PEEK( -16384): IF K <128  THEN  FOR K = 1 TO 25: NEXT K:K =  FRE(0):X =  RND(8): GOTO 4490
  453. 4500  PRINT  CHR$(7)
  454. 4510  POKE  -16368,0: REM      RESET KEYBOARD STROBE
  455. 4520  TEXT : HOME : RESTORE : RETURN 
  456. 4530  DATA   11,92,11,102,13,106,13,87,15,84,15,109,17,112,17,82, 19,80,19,116,21,118,21,78,23,76,23,121,25,123,25,75,27,74,27 ,125,29,127,29,74,31,73,31,128,33
  457. 4540  DATA   129,33,73,35,72,35,130,37,131,37,72,39,72,39,131,41 ,131,41,73,43,74,43,131,45,130,45,75,47,76,47,130,49,130,49, 77,51,78,51,129,53,128,53,78 
  458. 4550  DATA  37,58,37,64,39,66,39,57,41,57,41,67,43,67,43,58,45,61,45,68,47,68,47,64,52,68,52,74,54,75,54,66,56,61,56,74,58,73,58,58,60,56,60,71,62,69,62,54,64,52,64,66,66,63,66,51,68,53,68,60
  459. 4560  REM  <CTRL-J><CTRL-J>***  REWARD SUBROUTINE  ***
  460. 4570  HOME : POKE 49239,0: POKE 49232,0: FOR J = 1 TO 1000: NEXT : TEXT : FOR J = 1 TO 20: NEXT : RETURN 
  461. 4580  GOSUB 4260: FOR I = 1 TO 1000: NEXT : HOME : VTAB 8: PRINT "Note:  This program uses gambling as a  demonstration of an application of the  laws of probability.  Gambling is an    attempt to overcome the laws of"
  462. 4590  PRINT "probability.  This program is in no way intended to advocate gambling as an     activity."
  463. 4595  FOR I = 1 TO 5000: NEXT : PRINT  CHR$(4)"RUN STARTUP"
  464. 5000  END 
  465. 11000  REM   <CTRL-J><CTRL-J>*** SLOT SUBROUTINE ***<CTRL-J><CTRL-J>
  466. 11020  REM   SLOT -- FOR PROBABILITY
  467. 11030  GOSUB 4120
  468. 11040  HTAB 14: INVERSE : PRINT "THE BIG WIN": NORMAL 
  469. 11050  PRINT : PRINT : PRINT "Slot machines are a familiar gambling"
  470. 11060  PRINT "device.  Let's look at the probability"
  471. 11070  PRINT "of "; CHR$(34);"HITTING THE JACKPOT"; CHR$(34);" in a standard"
  472. 11080  PRINT  CHR$(34);"One Armed Bandit"; CHR$(34)
  473. 11090  VTAB 23: INPUT "Press return to continue...";Q$
  474. 11100  GOSUB 4140
  475. 11110  PRINT "A slot machine consists of 3 wheels"
  476. 11120  PRINT "with each wheel having 20 symbols.  In"
  477. 11130  PRINT "order to hit the jackpot, a seven must"
  478. 11140  PRINT "appear in all three windows:"
  479. 11150  HTAB 10: VTAB 10: PRINT "SEVEN   SEVEN   SEVEN"
  480. 11160  VTAB 23: INPUT "Press return for more...";Q$
  481. 11170  GOSUB 4160
  482. 11180  PRINT "On each wheel, only 1 out of 20 symbols"
  483. 11190  PRINT "is a SEVEN."
  484. 11200  PRINT : PRINT : PRINT "Therefore the probability of getting a"
  485. 11210  PRINT "SEVEN on one wheel is 1 out of 20 or a"
  486. 11220  PRINT "probability of .05."
  487. 11230  VTAB 23: INPUT "Press return to continue...";Q$
  488. 11240  GOSUB 4120
  489. 11250  HTAB 8: INVERSE : PRINT "THE ODDS ARE AGAINST US": NORMAL 
  490. 11260  PRINT : PRINT : PRINT "To find the odds of getting two sevens"
  491. 11270  PRINT "we must multiply the odds of getting a"
  492. 11280  PRINT "SEVEN in the first window by the odds"
  493. 11290  PRINT "of getting a SEVEN in the second window"
  494. 11300  VTAB 10: PRINT " 1      1        1"
  495. 11310  PRINT " --  X  --   =  ---"
  496. 11320  PRINT " 20     20      400"
  497. 11330  VTAB 23: INPUT "Press return to continue...";Q$
  498. 11340  GOSUB 4140
  499. 11350  PRINT "In order to get the jackpot, we need"
  500. 11360  PRINT "sevens in all three windows.  To"
  501. 11370  PRINT "calculate the probability of this"
  502. 11380  PRINT "we must multiply the individual chances"
  503. 11390  PRINT "of getting a SEVEN in each of the three"
  504. 11400  PRINT "windows:"
  505. 11410  PRINT : PRINT : PRINT 
  506. 11420  PRINT " 1      1      1     1"
  507. 11430  PRINT "--  X  --  X  --  = ----"
  508. 11440  PRINT "20     20     20    8000
  509. 11450  VTAB 16: PRINT "As you can see, the probability of"
  510. 11460  PRINT "hitting the jackpot is a tiny one"
  511. 11470  PRINT "chance out of 8000!  Written as a"
  512. 11480  PRINT "decimal, this is a probability of"
  513. 11490  PRINT ".000125  -  NOT VERY GOOD!"
  514. 11500  VTAB 24: INPUT "Press return to try to beat the odds...";Q$
  515. 11510  GOSUB 4160
  516. 11520  HTAB 10: INVERSE : PRINT "CAN YOU BEAT THE ODDS?": NORMAL 
  517. 11530  PRINT : PRINT "We will now do a computer simulation"
  518. 11540  PRINT "of a slot machine or " CHR$(34);"one armed bandit"; CHR$(34)"."
  519. 11550  PRINT : PRINT "Since our goal is to hit the jackpot,"
  520. 11560  PRINT "we won't worry about ways to win small"
  521. 11570  PRINT "amounts."
  522. 11580  VTAB 23: INPUT "Press return to play...";Q$
  523. 11590  HOME 
  524. 11600  HTAB 10: INVERSE : PRINT "NEWTON'S CASINO": NORMAL 
  525. 11610 W1 =  INT( RND(8) *20 +1)
  526. 11620 W2 =  INT( RND(8) *20 +1)
  527. 11630 W3 =  INT( RND(8) *20 +1)
  528. 11680  FOR I = 1 TO 20
  529. 11690  VTAB 10: PRINT  TAB( 7);WH$(21 -I); TAB( 17);WH$(I); TAB( 27);WH$(21 -I)
  530. 11700  VTAB 10: PRINT ; TAB( 38);" "
  531. 11710  NEXT I
  532. 11720  VTAB 10: HTAB 7: IF W1 = 7  THEN  INVERSE 
  533. 11730  PRINT WH$(W1);: NORMAL 
  534. 11740  PRINT  TAB( 17);: IF W2 = 7  THEN  INVERSE 
  535. 11750  PRINT WH$(W2);: NORMAL 
  536. 11760  PRINT  TAB( 27);: IF W3 = 7  THEN  INVERSE 
  537. 11770  PRINT WH$(W3)
  538. 11780  NORMAL 
  539. 11790  IF W1 = 7  AND W2 = 7  AND W3 = 7  THEN  VTAB 13: INVERSE : FOR I = 1 TO 10: PRINT  CHR$(7);: NEXT : PRINT : PRINT "CONGRATULATIONS...YOU BEAT THE ODDS!!!": NORMAL 
  540. 11800  VTAB 22: HTAB 1: PRINT "Press SPACEBAR to play again..."
  541. 11810  PRINT "...Q to quit..."
  542. 11820 K =  PEEK(49152): IF K <128  THEN 11820
  543. 11830  POKE 49168,0
  544. 11840  IF K -128 = 32  THEN 11590
  545. 11850  IF K -128 = 81  THEN 3950: REM    QUITTING MENU
  546. 11860  GOTO 11820